#!/usr/bin/env python

# Copyright 2012 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Model for Street Identity AP."""

from google.appengine.ext import db

__author__ = 'Maciej Machulak'
__maintainer__ = 'Maciej Machulak'
__email__ = 'mmachulak@google.com'

__copyright__ = 'Copyright 2012, Google Inc.'
__license__ = 'Apache License 2.0'
__version__ = '0.2'
__status__ = 'Prototype'


class User(db.Model):
  """User of the application."""

  email = db.StringProperty(required=True)
  display_name = db.StringProperty(required=True)
  refresh_token = db.StringProperty()
  credentials = db.BlobProperty()


class Attribute(db.Model):
  """Verified attribute of the user."""

  id = db.StringProperty(required=True)
  type = db.StringProperty(
      choices=('street_address', 'phone_number', 'birthday'))
  desc = db.StringProperty(required=True)
  value = db.StringProperty(required=True)
  user = db.ReferenceProperty(required=True)
  si_id = db.StringProperty(default='')
  si_location = db.StringProperty(default='')


class Session(db.Model):
  """Login session."""

  id = db.StringProperty(required=True)
  user = db.ReferenceProperty(User)
  access_token = db.StringProperty()


class Application(db.Model):
  """Registered Relying Party."""

  client_id = db.StringProperty(required=True)
  client_secret = db.StringProperty(required=True)


class Authorization(db.Model):
  """Authorization for RP."""

  access_token = db.StringProperty(required=True)
  iat = db.DateTimeProperty(required=True)
  exp = db.DateTimeProperty(required=True)
  refresh_token = db.StringProperty(required=True)
  token_type = db.StringProperty(required=True, choices=['Bearer'],
                                 default='Bearer')
  application = db.ReferenceProperty(required=True)
